import {
    getInfoByProject,
    // 基桩检测统计获取项目名称
    getProjectIdAndName,
    // 基桩检测统计获取施工单位名称
    getCompanyIdAndName,
} from "@/api/request.js";

import actions from "@/actions";
import TableLyout from '@/components/commonPublic/tableLyout.vue'
import TableData from "@/components/commonPublic/el-table"; //主页面列表
import formJs from "./regexDetail.js"; //新增弹框配置项
import publicForm from "@/components/PCManage/fromCom.vue"; //弹框form

export default {
    name: "section",
    data() {
        return {
            names: "section",
            projectsObj: [], //项目名
            tendersObj: [],
            falgId: null,
            editLoading: false,
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            getList: {
                fprojectid: "",
                fCompanyid: null, //机构id
                fUserid: null, //当前登录用户id
                sublevel: "1", //查看下级  1是0否
                page: 1, //页码
                pageSize: 15, //每页条数
                keyWord: "", // 选择状态
            },




            companyList: [], //检测状态：
            companyName: null,
            projectName: null,
            // 列表
            getList: {
                fDepartmentid: "", // 项目id
                fCompanyid: "", // 施工单位id
                keyWord: "", // 检测状态
                modelType: "2", // 0-按建设项目   1-按施工单位   2-按工程项目
                page: 1,
                pageSize: 20,
                fUserid: "",
                companyid: "",
            },
            navigatepageNums: null, //是否显示分页
            queryCriteriaData: {},
            formData: {},
            loading: false,
            tableData: [],
        };
    },
    mounted() {

        // this.userInfo = JSON.parse(sessionStorage.getItem("GxEmbedded_userInfo"));
        // this.getList.fUserid = this.userInfo.userId;
        // this.getList.companyid = this.userInfo.companyId;
        // this.yj_searchForm(this.getList);
        // // 项目名称数据
        // this.getProjectIdAndName();
        actions.onGlobalStateChange((state, prev) => {
            this.userInfo = prev.currentUser
            // console.log(4444, this.userInfo);

        }, true);

        this.getList.fUserid = this.userInfo.id;
        this.getList.fCompanyid = this.userInfo.companyId;
        if (JSON.parse(sessionStorage.getItem("GxEmbedded_pcManage_getList"))) {
            var getListStorage = JSON.parse(sessionStorage.getItem("GxEmbedded_pcManage_getList"));
            this.getList = getListStorage
            if (getListStorage.fprojectid != "") {}
            this.yj_searchForm(this.getList)

        } else {
            this.yj_searchForm(this.getList)
        }
    },
    components: {
        TableLyout,
        TableData,
        publicForm
    },
    methods: {
        reset(e) {
            this.getList = this.$options.data.call(this).getList
            this.getList.fprojectid = e
        },
        // 页面切换
        handleSizeChange(val) {
            return val;
        },
        handleCurrentChange(val) {
            this.getList.page = val;
            this.yj_searchForm(this.getList);
        },
        selectJudgetype(e) {
            if (e.fItemName == "==请选择==") {
                this.getList.keyWord = '';
            } else {
                this.getList.keyWord = e.fItemName;
            }
            // this.yj_searchForm(this.getList);
        },
        selectCompany(e) {
            this.companyName = e.F_ProjectName;
            this.getList.fDepartmentid = e.F_ProjectId;
            this.projectName = "";
            this.getList.fCompanyid = "";
            this.getCompanyIdAndName(e.F_ProjectId);

            // this.yj_searchForm(this.getList);
        },
        selectProject(e) {
            this.projectName = e.F_CompanyName;
            this.getList.fCompanyid = e.F_CompanyId;
            // this.yj_searchForm(this.getList);
        },
        getProjectIdAndName() {
            getProjectIdAndName({})
                .then((res) => {
                    if (res.errcode == 0) {
                        var arr = [{
                            F_ProjectId: "",
                            F_ProjectName: "请选择",
                        }, ];
                        this.companyList = arr.concat(res.data.projectList);
                    } else {
                       
                        this.$message.error({
                            content: "项目名称"+ res.msg,
                            duration: 1000
                        })
                        return false;
                    }
                })
                .catch(() => {
                    console.log("项目名称获取失败");
                    return false;
                });
        },
        getCompanyIdAndName(id) {
            getCompanyIdAndName({
                    projectId: id
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        var arr = [{
                            F_CompanyId: "",
                            F_CompanyName: "请选择",
                        }, ];
                        this.projectList = arr.concat(res.data.companyList);
                    } else {
                        this.$message.error({
                            content: "施工单位"+ res.msg,
                            duration: 1000
                        })
                        return false;
                    }
                })
                .catch(() => {
                    console.log("施工单位获取失败");
                    return false;
                });
        },

        //查看下级
        see() {
            if (this.checked == true) {
                this.getList.sublevel = 1;
            } else {
                this.getList.sublevel = 0;
            }
            this.yj_searchForm(this.getList);
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val;
        },
        getDetail() {
            if (this.equipmentDetailId != null && this.equipmentDetailId != "") {
                this.edit(1);
            } else {
        
                this.$message.warning;({
                    content: "请先选择需要编辑的数据",
                    duration: 1000
                })

            }
        },

        // 获取列表数据
        yj_searchForm(data) {
            this.loading = true;
            var that = this;
            var that = this;
            window.sessionStorage.setItem(
                "GxEmbedded_pcManage_getList",
                JSON.stringify(data)
            );
            var id;
            if(data.fCompanyid!=''){
              id=data.fCompanyid
            }else {
              id=data.fprojectid
            }
            var obj = {
                fprojectid: id,
                fCompanyid: data.fCompanyid, //机构id
                fUserid: data.fUserid, //当前登录用户id
                page: data.page, //页码
                pageSize: data.pageSize, //每页条数
                keyWord: data.keyWord, // 选择状态



            }
            getInfoByProject(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                        this.navigatepageNums =
                            this.queryCriteriaData.navigatepageNums.length;
                    } else {
                        this.loading = false;
              
                        this.$message.error({
                            content: "列表数据"+ res.msg,
                            duration: 1000
                        })
                    }
                })
                .catch((err) => {
                    console.log("列表接口", err);
                });
        },
    },
};